package game.module.turntables.dao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import db.proto.PlayTurntable.ATurntables;
import db.proto.PlayTurntable.PTurntable;
import game.module.turntables.bean.TurntableBean;
import game.module.turntables.logic.TurntableDBHelper;


public class TurntableCache {

	private static Logger logger = LoggerFactory.getLogger(TurntableCache.class);
	
	static class SingletonHolder {
		static TurntableCache instance = new TurntableCache();
	}

	public static TurntableCache getInstance() {
		return SingletonHolder.instance;
	}
	
	public Map<Integer,TurntableBean> turntableCacheAll = new ConcurrentHashMap<Integer,TurntableBean>();
	
	public void loadFromDb(int playerId) {
		if(turntableCacheAll.containsKey(playerId)) {
			return;
		}
		TurntableBean turntable = TurntableDBDao.getInstance().getTurntableById(playerId);
		if(turntable != null) {
			turntableCacheAll.put(playerId, turntable);
		}
		logger.info("playerId={} load turntable",playerId);
	}
	/**
	 * 下线删除
	 * */
	public void remove(int playerId) {
		turntableCacheAll.remove(playerId);
	}
	/**
	 * 获得设置
	 * **/
	public TurntableBean getTurntable(int playerId) {
		return turntableCacheAll.get(playerId);
	}
} 
